package com.pic.mgt.monitor.parser;

import com.pic.mgt.monitor.WrongUnitFormatException;

public final class MessageTerminalIdParser extends FormatParser {
	private int messageTerminalIdStartFromChar;
	private int messageTerminalIdEndToChar;

	@Override
	public Object parse(Object _messageConfirmationFilename) throws WrongUnitFormatException {
		super.checkObjectType(_messageConfirmationFilename, String.class);
		
		String messageConfirmationFilename = (String)_messageConfirmationFilename;
		
		try {
			String messageTerminalId = messageConfirmationFilename.
												substring(messageTerminalIdStartFromChar - 1,
														messageTerminalIdEndToChar);
			return messageTerminalId;
		} catch (IndexOutOfBoundsException e) {
			throw new WrongUnitFormatException(
					"The confirmation filename '" + messageConfirmationFilename +
					"' of message is not correct!");
		}
	}
	
	// --- getter and setter ---

	public void setMessageTerminalIdStartFromChar(int messageTerminalIdStartFromChar) {
		this.messageTerminalIdStartFromChar = messageTerminalIdStartFromChar;
	}

	public void setMessageTerminalIdEndToChar(int messageTerminalIdEndToChar) {
		this.messageTerminalIdEndToChar = messageTerminalIdEndToChar;
	}

}
